package gui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Image;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.Border;

public class gui {

	private static void addLabels(JPanel innerMainPanelCenterNorth) {
		innerMainPanelCenterNorth.setBackground(Color.black);
		JLabel label1Text = new JLabel("Input 1");
		label1Text.setFont(new Font("Times New Roman", Font.BOLD, 18));
		label1Text.setForeground(Color.WHITE);

		label1Text.setForeground(Color.WHITE);

		JLabel label2Text = new JLabel("                                      ");

		JLabel label3Text = new JLabel("Consensus");
		label3Text.setForeground(Color.WHITE);
		label3Text.setFont(new Font("Times New Roman", Font.BOLD, 18));

		JLabel label4Text = new JLabel("                                      ");

		JLabel label5Text = new JLabel("Input 2");
		label5Text.setForeground(Color.WHITE);
		label5Text.setFont(new Font("Times New Roman", Font.BOLD, 18));

		innerMainPanelCenterNorth.add(label1Text);
		innerMainPanelCenterNorth.add(label2Text);
		innerMainPanelCenterNorth.add(label3Text);
		innerMainPanelCenterNorth.add(label4Text);
		innerMainPanelCenterNorth.add(label5Text);

	}

	private static void addTextAreaSettings(JTextArea[] allTextAreas,
			String[] text1, String[] text2, String[] text3) {
		int counter = 0;
		for (JTextArea currentTextArea : allTextAreas) {

			currentTextArea.setEditable(false);
			currentTextArea.setLineWrap(true);
			currentTextArea.setWrapStyleWord(true);
//			currentTextArea.setOpaque(false);

			if (counter == 0) {
				for (String currentWord : text1) {
					currentTextArea.append(currentWord);
				}
			}
			if (counter == 1) {
				for (String currentWord : text2) {
					currentTextArea.append(currentWord);
				}
			}
			if (counter == 2) {
				for (String currentWord : text3) {
					currentTextArea.append(currentWord);
				}
			}
			counter++;
		}
	}

	public void buildGui(String[] text1, String[] text2, String[] text3) {
		JFrame frame = new JFrame();
		frame.setVisible(true);
		frame.setTitle("PlagiCheck");

		BackgroundPanel mainPanel = new BackgroundPanel("abstract");
		mainPanel.setLayout(new BorderLayout());

		JPanel mainPanelNorth = new JPanel();
		mainPanelNorth.setBackground(Color.BLACK);
		mainPanelNorth.setLayout(new FlowLayout());

		JLabel labelMainPanelNorth = new JLabel("PlagiCheck");
		labelMainPanelNorth.setFont(new Font("Times New Roman", Font.BOLD, 22));
		labelMainPanelNorth.setForeground(Color.WHITE);
		mainPanelNorth.add(labelMainPanelNorth);

		mainPanel.add(mainPanelNorth, BorderLayout.NORTH);

		JPanel mainPanelCenter = new JPanel();
		mainPanelCenter.setLayout(new FlowLayout());
		Border emptyBorder1 = BorderFactory.createEmptyBorder(36, 0, 0, 0);
		mainPanelCenter.setBorder(emptyBorder1);

		JPanel innerMainPanelCenter = new JPanel();
		innerMainPanelCenter.setBackground(Color.BLACK);
		Border emptyBorder2 = BorderFactory.createEmptyBorder(0, 10, 6, 10);
		innerMainPanelCenter.setBorder(emptyBorder2);
		innerMainPanelCenter.setLayout(new BorderLayout());

		JPanel innerMainPanelCenterNorth = new JPanel();
		addLabels(innerMainPanelCenterNorth);

		JPanel innerMainPanelCenterCenter = new JPanel();
		innerMainPanelCenterCenter.setBackground(Color.BLACK);
		
		JTextArea textAreaText1 = new JTextArea(16, 15);
		textAreaText1.setBackground(Color.BLACK);
		textAreaText1.setForeground(Color.WHITE);
		
		JTextArea textAreaUebereinstimmnug = new JTextArea(16, 15);
		textAreaUebereinstimmnug.setForeground(Color.WHITE);
		textAreaUebereinstimmnug.setBackground(Color.BLUE);

		JTextArea textAreaText2 = new JTextArea(16, 15);
		textAreaText2.setBackground(Color.BLACK);
		textAreaText2.setForeground(Color.WHITE);
		
		JTextArea[] allTextAreas = { textAreaText1, textAreaUebereinstimmnug,
				textAreaText2 };
		addTextAreaSettings(allTextAreas, text1, text2, text3);

		final JScrollPane textAreaText1ScrollPane = new JScrollPane(
				textAreaText1);
		final JScrollPane textAreaUebereinstimmnugScrollPane = new JScrollPane(
				textAreaUebereinstimmnug);
		final JScrollPane textAreaText2ScrollPane = new JScrollPane(
				textAreaText2);

		innerMainPanelCenterCenter.add(textAreaText1ScrollPane);
		innerMainPanelCenterCenter.add(textAreaUebereinstimmnugScrollPane);
		innerMainPanelCenterCenter.add(textAreaText2ScrollPane);

		JPanel innerMainPanelCenterSouth = new JPanel();
		innerMainPanelCenterSouth.setBackground(Color.BLACK);
		Border emptyBorder3 = BorderFactory.createEmptyBorder(2, 0, 3, 6);;
		innerMainPanelCenterSouth.setBorder(emptyBorder3);
		innerMainPanelCenterSouth.setLayout(new FlowLayout(FlowLayout.RIGHT, 0,
				0));

		JButton buttonScrollUp = new JButton();
		try {
			Image img = ImageIO.read(getClass().getResource("pfeilUp.png"));
			buttonScrollUp.setIcon(new ImageIcon(img));
		} catch (IOException ex) {
		}
		buttonScrollUp.setMargin(new Insets(3, 3, 3, 3));
		buttonScrollUp.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				textAreaText1ScrollPane.getVerticalScrollBar()
						.setBlockIncrement(50);

				textAreaText1ScrollPane.transferFocusDownCycle();
				textAreaText1ScrollPane.getVerticalScrollBar().setValue(
						textAreaText1ScrollPane.getVerticalScrollBar()
								.getValue()
								- textAreaText1ScrollPane
										.getVerticalScrollBar()
										.getBlockIncrement());

				textAreaUebereinstimmnugScrollPane.getVerticalScrollBar()
						.setBlockIncrement(50);

				textAreaUebereinstimmnugScrollPane.transferFocusDownCycle();
				textAreaUebereinstimmnugScrollPane.getVerticalScrollBar()
						.setValue(
								textAreaUebereinstimmnugScrollPane
										.getVerticalScrollBar().getValue()
										- textAreaUebereinstimmnugScrollPane
												.getVerticalScrollBar()
												.getBlockIncrement());

				textAreaText2ScrollPane.getVerticalScrollBar()
						.setBlockIncrement(50);

				textAreaText2ScrollPane.transferFocusDownCycle();
				textAreaText2ScrollPane.getVerticalScrollBar().setValue(
						textAreaText2ScrollPane.getVerticalScrollBar()
								.getValue()
								- textAreaText2ScrollPane
										.getVerticalScrollBar()
										.getBlockIncrement());

			}
		});

		JButton buttonScrollDown = new JButton();
		try {
			Image img = ImageIO.read(getClass().getResource("pfeilDown.png"));
			ImageIcon image = new ImageIcon(img);
			buttonScrollDown.setIcon(image);

		} catch (IOException ex) {
		}
		buttonScrollDown.setMargin(new Insets(3, 3, 3, 3));
		buttonScrollDown.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				textAreaText1ScrollPane.getVerticalScrollBar()
						.setBlockIncrement(50);

				textAreaText1ScrollPane.transferFocusDownCycle();
				textAreaText1ScrollPane.getVerticalScrollBar().setValue(
						textAreaText1ScrollPane.getVerticalScrollBar()
								.getValue()
								+ textAreaText1ScrollPane
										.getVerticalScrollBar()
										.getBlockIncrement());

				textAreaUebereinstimmnugScrollPane.getVerticalScrollBar()
						.setBlockIncrement(50);

				textAreaUebereinstimmnugScrollPane.transferFocusDownCycle();
				textAreaUebereinstimmnugScrollPane.getVerticalScrollBar()
						.setValue(
								textAreaUebereinstimmnugScrollPane
										.getVerticalScrollBar().getValue()
										+ textAreaUebereinstimmnugScrollPane
												.getVerticalScrollBar()
												.getBlockIncrement());

				textAreaText2ScrollPane.getVerticalScrollBar()
						.setBlockIncrement(50);

				textAreaText2ScrollPane.transferFocusDownCycle();
				textAreaText2ScrollPane.getVerticalScrollBar().setValue(
						textAreaText2ScrollPane.getVerticalScrollBar()
								.getValue()
								+ textAreaText2ScrollPane
										.getVerticalScrollBar()
										.getBlockIncrement());

			}
		});

		innerMainPanelCenterSouth.add(buttonScrollUp);
		innerMainPanelCenterSouth.add(buttonScrollDown);

		innerMainPanelCenter.add(innerMainPanelCenterNorth, BorderLayout.NORTH);
		innerMainPanelCenter.add(innerMainPanelCenterCenter,
				BorderLayout.CENTER);
		innerMainPanelCenter.add(innerMainPanelCenterSouth, BorderLayout.SOUTH);

		mainPanelCenter.setOpaque(false);
		mainPanelCenter.add(innerMainPanelCenter);

		mainPanel.add(mainPanelCenter);

		frame.setContentPane(mainPanel);
		frame.setSize(new Dimension(762, 503));
		frame.setLocationRelativeTo(null);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}
